﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TorchView.GameContent.Data;

namespace TorchView.GameContent.Units
{
  public sealed class Wardrobe : IDataSerializable
  {
    public const string BLOCK_NAME = "WARDROBE";

    #region IDataSerializable Members

    public DataBlock MakeDataBlock()
    {
      var block = Data == null ? new DataBlock(BLOCK_NAME) : Data;
      block.SetPropertyValue("CLASS", Class);
      block.SetOrClearPropertyValue(Texture != "", "TEXTURE", Texture);
      block.SetOrClearPropertyValue(Mesh != "", "MESH", Mesh);
      block.SetOrClearPropertyValue(ItemMesh != "", "ITEM_MESH", ItemMesh);
      block.SetOrClearPropertyValue(ItemMeshSecondary != "", "ITEM_MESH_SECONDARY", ItemMeshSecondary);
      block.SetOrClearPropertyValue(Icon != "", "ICON", Icon);
      return block;
    }

    public void LoadFromDataBlock(DataBlock block)
    {
      if (block == null)
        throw new ArgumentNullException("block");
      if (block.Name != BLOCK_NAME)
        throw new ArgumentException("Incorrect block type, only " + BLOCK_NAME + " is supported.");

      Data = block;
      Class = block.GetPropertyValue("CLASS", "");
      Texture = block.GetPropertyValue("TEXTURE", "");
      Mesh = block.GetPropertyValue("MESH", "");
      ItemMesh = block.GetPropertyValue("ITEM_MESH", "");
      ItemMeshSecondary = block.GetPropertyValue("ITEM_MESH_SECONDARY", "");
      Icon = block.GetPropertyValue("ICON", "");
    }

    #endregion

    public DataBlock Data { get; set; }

    public string Class { get; set; }
    public string Texture { get; set; }
    public string Mesh { get; set; }
    public string ItemMesh { get; set; }
    public string ItemMeshSecondary { get; set; }
    public string Icon { get; set; }
  }
}
